function [hamReturn spamReturn] = featureSelect(NHam, NSpam)
    % Selects features from e-mails by subtracting the number of words counted
    % in the ham-emails from the number of same words in spam-mails and the
    % other way around. The function returns the words that, after subtraction,
    % still has more than NHam or NSpam words left.
    %
    % INPUT: 
    %       NHam: minimum number of occurances needed to return this word as
    %       relevant for ham e-mails
    %       NSpam: minimum number of occurances needed to return this word as
    %       relevant for spam e-mails
    %
    % OUTPUT:
    %       (ham|spam)Return: words that occured in more than N(Ham|Spam)
    %       e-mails

    % The directory that leads us to ham or spam e-mails
    hamDir = 'ham/train/';
    spamDir = 'spam/train/';

    % Count the words in ham and spam e-mails
    ham = countwords(hamDir);
    spam = countwords(spamDir);
    
    % retrieve fields from ham and spam structs to loop through
    fieldsHam = fieldnames(ham);
    fieldsSpam = fieldnames(spam);

    sameWords = 0;
    % Create difference-struct
    fieldsHamDifference = fieldsHam;
    for i = 1:size(fieldsHam)
        if(isfield(spam, fieldsHam{i}))
            % subtract number of times this word is in the spam e-mails
            fieldsHamDifference.(fieldsHam{i}) = ham.(fieldsHam{i}) - spam.(fieldsHam{i});
            sameWords = sameWords + 1;
        end
    end

    sameWords

    fieldsSpamDifference = fieldsSpam;
    for i = 1:size(fieldsSpam)
        if(isfield(ham, fieldsSpam{i}))
            % subtract number of times this word is in the spam e-mails
            fieldsSpamDifference.(fieldsSpam{i}) = spam.(fieldsSpam{i}) - ham.(fieldsSpam{i});
        end
    end
    
    [hamWords hamIndices] = wordtable(fieldsHamDifference, fieldsHamDifference);
    [spamWords spamIndices] = wordtable(fieldsSpamDifference, fieldsSpamDifference);
    hamReturn = hamWords(find(hamIndices(:, 1) > NHam))
    spamReturn = spamWords(find(spamIndices(:, 1) > NSpam))
end
